<template>
  <div>
    <div>
      <card-container  key="container3"  style="margin-top: 16px" :title="rightConTitle">
        <topic-card :from="from" v-if="rightList.length>0" v-for="(val,index) in rightList" :key="val.topicId" :info="val"></topic-card>
        <empty-card v-if="rightList.length===0" height="556px"></empty-card>

      </card-container>
      <pagination key="container5" style="margin:20px auto;" :pages="pages" v-on:listenPageChange="changePage"></pagination>
    </div>
  </div>
</template>


<script>
  import ProjectCard from '../../../components/pc/projectCard';
  import TopicCard from '../../../components/pc/topicCard';
  import CardContainer from '../../../components/pc/cardContainer';
  import config from '../../../action/config';
  import Pagination from "../../../components/pc/pagination";
  import EmptyCard from "../../../components/pc/emptyCard";

  export default {
    name:'topic',
    data(){
      return{
        leftList:[],
        rightList:[],
        pages:1,
        from:'my'
      }
    },
    computed:{
      rightConTitle(){
        if(this.$route.query.type==="my"){
          return '我创建的话题'
        }
        if(this.$route.query.type==="notice"){
          return '我关注的话题'
        }
      },    },
    components:{
      ProjectCard,CardContainer,TopicCard,Pagination,EmptyCard
    },
    methods:{
      dataGetMyTopic(currentPage){
        this.from = 'my';
          this.$axios.$get(config.api.get.Topic.myList, {
            params: {
              page: currentPage,
              size: 10
            }
          }).then((response) => {
            this.rightList = response.data.dataList;
            this.pages = response.data.totalPage;
          })
      },

      dataGetNoticeTopic(currentPage){
        this.from = 'notice';
        this.$axios.$get(config.api.get.Topic.myfollowedList,{
          params:{
            page:currentPage,
            size:10
          }
        }).then((response)=>{
            this.rightList = response.data.records;
            this.pages =  response.data.pages;
        })
      },

      changePage(currentPage){
        //返回页数 请求新的数据
        let type = this.$route.query.type
        if(type==='my'){
          this.dataGetMyTopic(currentPage);
        }
        if(type==='notice'){
          this.dataGetNoticeTopic(currentPage);
        }
      }


    },
  }
</script>

<style lang="scss">

</style>
